//
//  DiscoveryViewController.m
//  聊吧
//
//  Created by 刘洋 on 16/6/13.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "DiscoveryViewController.h"
#import "DiscoveryTableViewCell.h"
#import "PedomViewController.h"
#import "SweepViewController.h"

//#import "PedometerViewController.h"

#import "NearbyViewController.h"
#import "FriendsterViewController.h"

static NSString *const discoveryCell = @"DiscoveryCELL";
@interface DiscoveryViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)BaseTableView *discoveryTableView;


@end



@implementation DiscoveryViewController

-(void)dealloc
{
    [_discoveryTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    self.navigationItem.title = @"发现";
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.discoveryTableView = [[BaseTableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.discoveryTableView.backgroundColor = RGBAColor(239, 239, 244);
    [self.view addSubview:self.discoveryTableView];
    [self.discoveryTableView release];
    self.discoveryTableView.delegate = self;
    self.discoveryTableView.dataSource = self;
    
    self.discoveryTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //注册
    [self.discoveryTableView registerClass:[DiscoveryTableViewCell class] forCellReuseIdentifier:discoveryCell];
    
    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return 2;
    }
    return 1;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DiscoveryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:discoveryCell forIndexPath:indexPath];
    if (indexPath.section == 0) {
       
        cell.label.text = @"朋友圈" ;
        cell.image.image = [UIImage imageNamed:@"more_icon_zhifubao_friend"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
    }
    if (indexPath.section == 1) {
        
        NSArray *array = @[@"扫一扫",@"计步器"];
        NSArray *arrayImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"more_icon_code"],[UIImage imageNamed:@"more_icon_dingding"], nil];
        cell.label.text = array[indexPath.row];
        cell.image.image = arrayImage[indexPath.row];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
    }
    
      cell.label.text = @"我的周边(摇一摇返回)";
    cell.image.image = [UIImage imageNamed:@"more_laiwang"];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        FriendsterViewController *friendsterVC = [[FriendsterViewController alloc] init];
        //跳转隐藏tabBar
        friendsterVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:friendsterVC animated:YES];
      //  [friendsterVC release];
        
    }
    
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            
            SweepViewController *sweepVC = [[SweepViewController alloc] init];
          //  sweepVC.type = @"11";
            sweepVC.hidesBottomBarWhenPushed = YES;
             sweepVC.isAddFriend = NO;
            [self.navigationController pushViewController:sweepVC animated:YES];
            [sweepVC release];
            
        }
        if(indexPath.row == 1){
            
        PedomViewController *pedometerVC = [[PedomViewController alloc] init];
            pedometerVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:pedometerVC animated:YES];
         [pedometerVC release];
            
        }
            
    }
    if (indexPath.section == 2) {
        
        NearbyViewController *nearbyVC = [[NearbyViewController alloc] init];
        nearbyVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:nearbyVC animated:YES];
        [nearbyVC release];
    }
    
    
}

//section跟tableView一起滚动的方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.discoveryTableView)
    {
        CGFloat sectionHeaderHeight = 20;
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y,0, 0, 0);
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}
@end
